<!-- 首页 -->
<template>
  <div class="scenichome" ref="homePage">

    <!-- <p id='adcode'></p> -->
    <div style="height:60px;display: flex;align-items: center;position: fixed;width: 100%;background: #46d0ca;justify-content: center;z-index: 99;">
      <div class="search">
        <div @click="select" class="search_cs">
          <span>{{current}}</span>
          <van-icon name="arrow-down" />
        </div>
        <div class="search_in">
          <!-- <input v-model="search_value" placeholder="搜索想要的旅游产品或服务" type="text"  /> -->
          <form action="/">
            <van-search placeholder="搜索想要的旅游产品或服务" v-model="search_value" @search="issuecontent" />
          </form>
        </div>
        <div id="container"></div>
        <!-- <div style="display: flex;align-items: center;">
          <van-icon name="search" color="#00CBA6" size="24" />
        </div> -->
      </div>
    </div>
    <van-popup position="" style="width: 100%;height: 100%;" v-model="show">
      <van-nav-bar title="城市列表" left-arrow @click-left="onClickLeft" />
      <div style="width: 100%;height: 46px;"></div>
      <div class="current">
        <div class="current_box">
          <span>当前城市</span>
          <span style="color: #00CBA6;">{{current}}</span>
        </div>
        <div class="current_box">
          <span>定位城市</span>
          <span style="color: #00CBA6;display: flex;align-items: center;">
            <van-icon name="location" size="16px" />{{chengshi}}</span>
        </div>
      </div>
      <div class="popular">
        <p class="popular_p">热门城市</p>
        <div style="display: flex;flex-wrap: wrap;justify-content: space-around;">
          <div @click="popularCs(itme)" class="popular_cs" v-for="(itme,index) in Popular" :kye='index'>{{itme}}</div>
        </div>
      </div>
      <!-- <div> -->
      <van-index-bar :index-list="nameData">
        <div v-for="(data,index) in ityList" :key="index">
          <van-index-anchor :index="data.id">{{data.name}}</van-index-anchor>
          <van-cell @click="cell(res.name)" v-for="(res,index) in data.content" :key="index" :title="res.name" />
        </div>
      </van-index-bar>

    </van-popup>

    <!-- 头部以下 -->
    <div class="sort">
      <van-dropdown-menu active-color="#51c5b8" style="background: rgba(240, 240, 240, 1);">
        <div style="width: 1px;height: 20px;border: 1px solid rgb(225, 225, 225);position: absolute;left: 51%;top: 10px;"></div>
        <van-dropdown-item style="" v-model="value1" :options="option1" @change="changeabout" />

        <van-dropdown-item title="筛选" ref="item">
          <div class="filter">
            <div class="filter_neo">
              <div style="height: 40px;line-height: 40px;">景区级别</div>
              <van-checkbox-group active-color="#51c5b8" v-model="result" @change="changeValue" style="display: flex;justify-content: space-between;">
                <van-checkbox shape="square" checked-color="#51c5b8" name='0'>不限</van-checkbox>
                <van-checkbox shape="square" checked-color="#51c5b8" name='1' :disabled="isDisabled" v-model="checked">四星</van-checkbox>
                <van-checkbox shape="square" checked-color="#51c5b8" name='2' :disabled="isDisabled" v-model="checked">五星&#12288;&#12288;</van-checkbox>
              </van-checkbox-group>
            </div>
            <div class="filter_two">
              <div style="height: 40px;line-height: 40px;">景区类型</div>
              <van-checkbox-group v-model="view" @change="changeview">
                <van-checkbox shape="square" checked-color="#51c5b8" name='0'>不限</van-checkbox>
                <van-checkbox shape="square" checked-color="#51c5b8" style="margin-left: 34px;" name='1' :disabled="Disabled" v-model="viewcheck">湖光山色</van-checkbox>
                <van-checkbox shape="square" checked-color="#51c5b8" name='2' :disabled="Disabled" v-model="viewcheck">古迹遗址</van-checkbox>
                <van-checkbox shape="square" checked-color="#51c5b8" name='3' :disabled="Disabled" v-model="viewcheck">田园度假</van-checkbox>
                <van-checkbox shape="square" checked-color="#51c5b8" name='4' :disabled="Disabled" v-model="viewcheck">漂流戏水</van-checkbox>
                <van-checkbox shape="square" checked-color="#51c5b8" name='5' :disabled="Disabled" v-model="viewcheck">民俗风情</van-checkbox>
                <van-checkbox shape="square" checked-color="#51c5b8" name='6' :disabled="Disabled" v-model="viewcheck">动植物园</van-checkbox>

              </van-checkbox-group>
            </div>
          </div>
          <van-button block type="info" color="#51c5b8" @click="infovalue">确认</van-button>
        </van-dropdown-item>
      </van-dropdown-menu>
    </div>
    <div style="width: 100%;height: 100px;"></div>
    <div v-show="deviceList.length == 0" class="wudingdan">
      <van-icon name="description" />
      <p>亲,暂无相关数据哦</p>
    </div>
    <div v-show="deviceList.length != 0" class="list">
      <!-- <van-divider style="color: #000000;">最新商品</van-divider> -->
      <!-- <van-pull-refresh v-model="isLoading" @refresh="onRefresh"> -->
      <van-list v-model="loading" :finished="finished" finished-text="没有更多了" @load="onLoad">
        <div class="commodity" @click="commodity(itme.resSN)" v-for="(itme,index) in deviceList" :key="index">
          <div class="commodity-img">
            <img :src="itme.Cover">
          </div>
          <div class="commodity-details">
            <div class="details-teile">
              <span style="color: rgb(40, 40, 40);">{{itme.Name}}{{itme.TypeStr}}</span>&#8194;
              <span style="color: #46d0ca;">{{itme.Score}}分</span>
            </div>
            <div style="display: flex;">
              <div style="margin-left: 5px;">
                <van-tag v-for="(data,index) in itme.Tags" :key="index" style="border: 1px solid;margin-right: 4px;" size="20px" plain color="#46d0ca">{{data}}</van-tag>
              </div>
            </div>
            <div class="deleted-content">
              <p>{{itme.Info}}</p>
            </div>
            <div class="deleted-km">
              <p> <span v-if="parseInt(itme.DistanceStr)>0">距您{{itme.DistanceStr}}</span> </p>
              <div style="width: 40%;text-align: center;">
                <span style="font-size: 20px; color: #46d0ca;">￥{{itme.Price}}</span>
                <span>起</span>
              </div>
            </div>
          </div>
        </div>

      </van-list>

      <!-- </van-pull-refresh> -->
      <!-- 加载动画 -->
      <!-- <van-loading id="loading" size="30px" type="spinner" color="#FFFFFF" vertical>加载中...</van-loading> -->
      <div style="height: 40px;"></div>
    </div>

    <v-min></v-min>
  </div>
</template>

<script>
import city from '@/assets/js/city.js'
import data from '@/assets/js/data.js'
import AMap from 'AMap'
import min from '@/views/Min.vue'
import {
  resourceList
} from '@/api/home.js'
export default {
  components: {
    'v-min': min
  },
  // watch: {
  //   ass: function(val) {
  //     console.log(val)
  //   }
  // },
  data () {
    return {
      clintHeigth: '', // 获取页面高度
      // 头部
      show: false, // 控制城市弹出层
      chengshi: '', // 定位
      current: '', // 选择城市
      search_value: '', // 输入框
      nameData: [ // 定义一个索引
        'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V',
        'W',
        'X', 'Y', 'Z'
      ],
      Popular: ['上海', '北京', '广州', '深圳', '武汉', '天津', '西安', '南京', '杭州', '成都', '重庆', '郑州'],
      ityList: city, // 城市数组
      // ass: '',
      // data:data,//模拟数据

      // 请求景区列表
      deviceList: [],
      loading: false, // 控制上拉加载的加载动画
      finished: false, // 控制在页面往下移动到底部时是否调用接口获取数据
      totalPage: 0,
      pageNumber: 0, // 自定义一个变量
      Identification: '', // 跳转标识

      partInfo: '',
      // 筛选
      value1: 1,
      option1: [{
        text: '推荐排序',
        value: 1
      },
      {
        text: '离我最近',
        value: 2
      },
      {
        text: '销量最高',
        value: 3
      },
      {
        text: '评分最高',
        value: 4
      },
      {
        text: '价格最高',
        value: 5
      }
      ],
      // 级别筛选
      result: [],
      checked: false,
      isDisabled: false,
      // 类型筛选
      view: [],
      viewcheck: false,
      Disabled: false,
      level: '',
      Typesof: ''
    }
  },
  methods: {
    // 头部
    mapinit () { // 定位
      let that = this
      let map = new AMap.Map('container', {
        enableHighAccuracy: true,
        resizeEnable: true,
        center: [114.085947, 22.547],
        zoom: 8
      })
      // document.getElementById('adcode').innerHTML = '当前城市adcode：' + map.getAdcode() + '<br>' +
      //   '当前中心点：' + map.getCenter()
      // 获取用户所在城市信息
      function showCityInfo () {
        // 实例化城市查询类
        let citysearch = new AMap.CitySearch()
        // 自动获取用户IP，返回当前城市
        citysearch.getLocalCity((status, result) => {
          // console.log(result)
          if (status === 'complete' && result.info === 'OK') {
            if (result && result.city && result.bounds) {
              // console.log(JSON.stringify(result));
              let cityinfo = result.city
              let citybounds = result.bounds
              that.chengshi = cityinfo
              that.current = cityinfo
              // document.getElementById('info').innerHTML = '您当前所在城市：' + cityinfo;
              // 地图显示当前城市
              map.setBounds(citybounds)
            }
          } else {
            // document.getElementById('info').innerHTML = result.info;
            // console.log(result)
          }
        })
      }
      showCityInfo()
    },
    select () { // 打开选择城市
      this.show = true
    },
    cell (e) { // 选择城市
      this.current = e
      this.show = false
      // console.log(e)
      this.deviceList = []
      this.pageNumber = 0
      this.onLoad()
      this.$forceUpdate()
    },
    popularCs (e) { // 选择热门城市
      this.current = e
      this.show = false
      this.deviceList = []
      this.pageNumber = 0
      this.onLoad()
      this.$forceUpdate()
    },
    onClickLeft () { // 关闭选择城市
      this.show = false
    },
    // ---------------------------------
    // 头部以下
    changeabout (value) { // 排序
      this.deviceList = []
      this.pageNumber = 0
      this.onLoad()
      this.$forceUpdate()
      // console.log(value);
      // console.log(this.value1)
    },
    // 类型筛选
    changeview (value) {
      console.log(value)
      if (value.includes('0')) {
        this.Disabled = true
      } else {
        this.Disabled = false
      }
      this.Typesof = value
      if (value[0] == 0) {
        this.Typesof = {}
      }
    },
    // 级别筛选
    changeValue (value) {
      if (value.includes('0')) {
        this.isDisabled = true
      } else {
        this.isDisabled = false
      }
      this.level = value
      if (value[0] == 0) {
        this.level = ''
      }
    },
    infovalue () { // 确定筛选
      this.$refs.item.toggle()
      this.deviceList = []
      this.pageNumber = 0
      this.onLoad()
      this.$forceUpdate()
    },
    // 点击搜索
    issuecontent () {
      this.deviceList = []
      this.pageNumber = 0
      this.onLoad()
      this.$forceUpdate()
    },

    // 点击跳转
    commodity (resSN) {
      this.$router.push({
        path: '/Scenic/product',
        query: {
          resSN: resSN
        }
      })
    },

    // 第一次请求
    onLoad () {
      let self = this
      let mylan = this.lan + ',' + this.lat
      // console.log(this.lan)
      setTimeout(() => {
        let data = {
          PageNo: self.pageNumber + 1,
          MyLng: mylan, // 经纬度
          Category: 1,
          // City: this.current, //城市
          Name: this.search_value, // 搜索
          SortType: this.value1, // 排序
          Type: this.level, // 级别
          Tags: this.Typesof // 类型
        }
        resourceList(data).then(res => {
          console.log(res)
          if (res.List && res.List.length > 0) {
            self.totalPage = res.PageCount
            if (res.List.length > 0) {
              self.deviceList = self.deviceList.concat(res.List)
            } else {
              this.deviceList = res.List
            }
            self.loading = false
            self.pageNumber++
            if (self.pageNumber >= self.totalPage) {
              self.finished = true
            }
          }
        })
      }, 500)
    }

  },
  mounted () {
    this.search_value = this.$route.query.value
    if (sessionStorage.getItem("city")) {
      this.current = sessionStorage.getItem("city")
    } else {
      this.mapinit()
    }
    this.onLoad()
    this.clientHeight = `${document.documentElement.clientHeight}` // document.body.clientWidth;
    // console.log(this.clientHeight);
    this.$refs.homePage.style.minHeight = this.clientHeight + 'px'
    // console.log(this.partInfo);
  },
  watch: {
    isDisabled (val, oldVal) {
      // console.log(val)
      if (val == true) {
        this.result = []
        // this.checked = false
        this.result = ['0']
      }
    },
    Disabled (val, oldVal) {
      // console.log(val)
      if (val == true) {
        this.view = []
        // this.checked = false
        this.view = ['0']
      }
    }
  }
}
</script>
<style lang="scss">
.scenichome {
  background: white;

  .search {
    width: 90%;
    margin: 0 auto;
    display: flex;
    background: white;
    height: 40px;
    border: 1px solid #46d0ca;
    border-radius: 30px;

    .search_cs {
      display: flex;
      align-items: center;
      justify-content: center;
      width: 90px;
      .van-icon {
        font-size: 14px !important;
        margin-left: 5px;
      }
    }

    .search_in {
      display: flex;
      align-items: center;
      width: 60%;
      .van-search {
        padding: 0 !important;
        background: #ffffff;
        .van-search__content {
          background: none;
          .van-cell {
            border-left: 1px solid rgb(225, 225, 225);
            padding: 0px 0px 0px 10px;
            background: none;
            input {
              background: none;
            }
          }
        }
      }
      // input {
      //   border: none;
      //   border-left: 1px solid #999999;
      //   border-radius: 0 !important;
      // }
    }
  }

  .current {
    display: flex;
    padding: 0.625rem 1rem;
    line-height: 2rem;
    font-size: 14px;
    background: #ffffff;
    justify-content: space-between;
    color: #999999;

    .current_box {
      width: 50%;
      display: flex;
      justify-content: space-around;
    }
  }

  .popular {
    .popular_p {
      padding: 10px 16px;
      background: #f5f5f5;
      font-size: 14px;
    }

    .popular_cs {
      width: 80px;
      height: 30px;
      margin: 0.625rem 0.625rem;
      border-radius: 1.875rem;
      border: 1px solid #e4e4e4;
      display: flex;
      font-size: 14px;
      align-items: center;
      justify-content: center;
    }
  }

  .van-index-bar {
    color: #999999 !important;

    .van-index-anchor {
      background: #f5f5f5;
      color: #999999 !important;
      font-weight: 600;
    }

    .van-cell {
      color: #999999 !important;
    }
  }

  .van-popup {
    // top: 0;
    // transform:translate3d(0,0%,0) !important;
    .van-nav-bar {
      .van-nav-bar__left {
        .van-icon {
          font-size: 22px;
          color: white !important;
        }
      }
    }
  }

  .sort {
    position: fixed;
    position: fixed;
    width: 100%;
    top: 60px;
    z-index: 999;

    .van-dropdown-menu {
      width: 100%;
      position: fixed;
      top: 60px;
    }

    .filter {
      width: 100%;
      height: 240px;
      display: flex;
      flex-direction: column;
      align-items: center;

      .filter_neo {
        display: flex;
        flex-direction: column;
        width: 80%;
        height: 40%;

        .van-checkbox-group {
          display: flex;

          .van-checkbox__icon--checked .van-icon {
            background-color: #46d0ca !important;
            border-color: #46d0ca !important;
          }

          .van-checkbox__icon {
            .van-icon {
              color: white !important;
              font-size: 15px !important;
            }
          }
        }
      }

      .filter_two {
        display: flex;
        flex-direction: column;
        width: 80%;

        // height: 50%;
        .van-checkbox-group {
          display: flex;
          flex-wrap: wrap;
          justify-content: space-between;

          // .van-checkbox{
          //   .van-checkbox__icon{
          //     // font-size: 18px !important;
          //     color: white;
          //   }
          // }
          .van-checkbox__icon--checked .van-icon {
            background-color: #46d0ca !important;
            border-color: #46d0ca !important;
          }

          .van-checkbox__icon {
            .van-icon {
              color: white !important;
              font-size: 15px !important;
            }
          }

          div {
            // width: 33%;
            margin-top: 0.3125rem;
          }
        }
      }
    }
  }

  .list {
    .van-list {
      .commodity {
        position: relative;
        display: flex;
        width: 100%;
        height: 140px;
        /* background: #000000; */
        justify-content: center;
        align-items: center;
        border-bottom: 0.0625rem solid #f2f2f2;

        .commodity-img {
          display: flex;
          width: 40%;
          height: 80%;
          /* align-items: center; */
          /*垂直居中*/
          justify-content: center;

          /*水平居中*/
          img {
            display: flex;
            width: 90%;
            height: 90%;
            border-radius: 0.625rem;
          }
        }

        .commodity-details {
          width: 100%;

          /* display: flex; */
          /* justify-content: center; */
          /* align-items: center; */
          .details-teile {
            height: 1.875rem;
            line-height: 1.875rem;
            font-size: 16px;
          }

          .deleted-content {
            width: 95%;
            margin-top: 0.3125rem;
            font-size: 12px;
            color: #909090;
          }

          .deleted-km {
            display: flex;
            justify-content: space-between;
            margin-top: 0.625rem;
            font-size: 12px;
            color: #909090;
          }
        }
      }
    }
  }
}
</style>
